home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / disk-tools / hd-tools / scsi_tape / source.lha / util / skipfilemark.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-16  |  2.9 KB  |  163 lines

  1.  
  2. /*
  3.  *  SKIPFILEMARK.C
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/ports.h>
  8. #include <exec/io.h>
  9. #include <exec/memory.h>
  10. #include <devices/scsidisk.h>
  11. #include <libraries/dos.h>
  12. #include <libraries/dosextens.h>
  13. #include <libraries/filehandler.h>
  14. #include <clib/exec_protos.h>
  15. #include <clib/alib_protos.h>
  16.  
  17. typedef unsigned char ubyte;
  18.  
  19. typedef struct MsgPort    MsgPort;
  20. typedef struct IOStdReq IOStdReq;
  21. typedef struct SCSICmd    SCSICmd;
  22.  
  23. typedef struct SCSIReq {
  24.     IOStdReq sr_Req;
  25.     SCSICmd  sr_Cmd;
  26. } SCSIReq;
  27.  
  28. MsgPort *IoSink;
  29. SCSIReq Ios;
  30.  
  31. char *ErrorAry[] = {
  32.     "No Sense",
  33.     "Recovered Error",
  34.     "Not Ready",
  35.     "Medium Error",
  36.     "Hardware Error",
  37.     "Illegal Request",
  38.     "Unit Attention",
  39.     "Data Protect",
  40.     "Blank Check",
  41.     "Vendor Specific",
  42.     "Copy Aborted",
  43.     "Aborted Command",
  44.     "Equal (search_data)",
  45.     "Volume Overflow",
  46.     "MisCompare",
  47.     "Reserved",
  48.     "Unknown Error"
  49. };
  50.  
  51. void myexit(void);
  52.  
  53. main(ac, av)
  54. char *av[];
  55. {
  56.     char skipCmd[] = { 0x11, 0x01, 0x00, 0x00, 0x01, 0x00 };
  57.     int error;
  58.  
  59.     atexit(myexit);
  60.  
  61.     IoSink = CreatePort(NULL, 0);
  62.  
  63.     if (SCSIOpen("scsi.device", 4) < 0) {
  64.     puts("Unable to open scsi.device");
  65.     exit(20);
  66.     }
  67.     if (ac == 2) {
  68.     long n = strtol(av[1], NULL, 0);
  69.     skipCmd[2] = n >> 16;
  70.     skipCmd[3] = n >> 8;
  71.     skipCmd[4] = n;
  72.     }
  73.     if (error = DoSCSI(skipCmd, NULL, 0, SCSIF_READ, NULL))
  74.     printf("error %d %s\n", error, ErrorAry[(error >= 0 && error < 16) ? error : 16]);
  75.     return(0);
  76. }
  77.  
  78. void
  79. myexit(void)
  80. {
  81.     SCSIClose();
  82.     if (IoSink)
  83.     DeletePort(IoSink);
  84. }
  85.  
  86.  
  87. int
  88. SCSIOpen(devName, unitNo)
  89. char *devName;
  90. long unitNo;
  91. {
  92.     int error;
  93.  
  94.     Ios.sr_Req.io_Message.mn_ReplyPort = IoSink;
  95.     if (error = OpenDevice(devName, unitNo, &Ios.sr_Req, 0))
  96.     error = -1;
  97.     return(error);
  98. }
  99.  
  100. int
  101. SCSIClose()
  102. {
  103.     if (Ios.sr_Req.io_Device) {
  104.     CloseDevice(&Ios);
  105.     Ios.sr_Req.io_Device = NULL;
  106.     }
  107. }
  108.  
  109. int
  110. DoSCSI(cmd, buf, bytes, flags, len)
  111. char *cmd;
  112. char *buf;
  113. long bytes;
  114. ubyte flags;
  115. long *len;
  116. {
  117.     static ubyte senseCmd[] = { 0x03, 0x00, 0x00, 0x00, 20, 0 };
  118.     SCSIReq *ios = &Ios;
  119.     char senseBuf[20];
  120.     int error;
  121.  
  122.     ios->sr_Cmd.scsi_Command   = cmd;
  123.     ios->sr_Cmd.scsi_CmdLength = 6;
  124.     ios->sr_Cmd.scsi_Data   = buf;
  125.     ios->sr_Cmd.scsi_Length = bytes;
  126.     ios->sr_Cmd.scsi_Flags  = flags;
  127.  
  128.     ios->sr_Req.io_Command = 28;
  129.     ios->sr_Req.io_Data    = &ios->sr_Cmd;
  130.     ios->sr_Req.io_Length  = sizeof(ios->sr_Cmd);
  131.  
  132.     error = DoIO(&ios->sr_Req);
  133.     if (len)
  134.     *len = ios->sr_Cmd.scsi_Actual;
  135.  
  136.     switch(error) {
  137.     case 0:
  138.     break;
  139.     case HFERR_BadStatus:
  140.     ios->sr_Cmd.scsi_Command   = senseCmd;
  141.     ios->sr_Cmd.scsi_CmdLength = 6;
  142.     ios->sr_Cmd.scsi_Data    = (UWORD *)senseBuf;
  143.     ios->sr_Cmd.scsi_Length = sizeof(senseBuf);
  144.     ios->sr_Cmd.scsi_Flags    = SCSIF_READ;
  145.  
  146.     if (DoIO(&ios->sr_Req)) {
  147.         error = -256;
  148.         break;
  149.     }
  150.     if (ios->sr_Cmd.scsi_Actual < 4) {
  151.         error = -257;
  152.         break;
  153.     }
  154.     error = senseBuf[2];
  155.     break;
  156.     default:
  157.     error = -error;
  158.     break;
  159.     }
  160.     return(error);
  161. }
  162.  
  163.